package com.lanren.familybookapp.ui.me.presenter;

import com.lanren.common.base.impl.BasePresenter;
import com.lanren.familybookapp.ui.me.interfaces.IEmailModel;
import com.lanren.familybookapp.ui.me.model.EmailModel;

/**
 * @ClassName EmailPresenter
 * @Description TODO
 * @Author chongheng.wang
 * @Date 2019/10/11 19:11
 * @Version 1.0
 */
public class EmailPresenter extends BasePresenter<IEmailModel.IEmailView> {
    private EmailModel emailModel;

    public EmailPresenter() {
        emailModel = new EmailModel();
    }

    public void getEmailCode(String email) {
        emailModel.getEmailCode(email, new IEmailModel.EmailModel() {
            @Override
            public void onError(String data) {
                mRootView.showMessage(data);
            }

            @Override
            public void onSuccess(String msg) {
            }
        });
    }

    public void addEmailCode(String email, String emailCode) {
        mRootView.showLoading();
        emailModel.addEmailCode(email, emailCode, new IEmailModel.EmailModel() {
            @Override
            public void onError(String data) {
                mRootView.showComplete();
                mRootView.showMessage(data);
            }

            @Override
            public void onSuccess(String msg) {
                mRootView.showComplete();
                mRootView.onSuccessEmail(msg);
            }
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (emailModel != null) {
            emailModel.clearDisposable();
            emailModel = null;
        }
    }
}
